# polls/tests.py
from django.test import TestCase
from django.urls import reverse
from .models import Question, Choice

class PollsViewTests(TestCase):
    def test_index_view_with_no_questions(self):
        response = self.client.get(reverse('polls:index'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "暂无投票问题")

    def test_add_question_view(self):
        response = self.client.post(reverse('polls:add_question'), {
            'question_text': 'Test question',
            'choice_text': ['Choice 1', 'Choice 2']
        })
        self.assertEqual(response.status_code, 302)
        self.assertEqual(Question.objects.count(), 1)
        self.assertEqual(Choice.objects.count(), 2)